package page.sample.AdministratorPage;

import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.SubmitLink;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.model.CompoundPropertyModel;

import page.sample.AuthorizationPage;
import dao.impl.ClientDao;
import entity.Client;
import entity.CreditCard;
import entity.Operations;

public class AddCreditCardPage extends WebPage{
	
	public AddCreditCardPage(final Client client) {
	
		final ClientDao clientDao = new ClientDao(app.MyFirstWebApplication.DATA_XML_FOLDER);
		final CreditCard creditCard = new CreditCard();
		final Operations oper = new Operations();
		Form<CreditCard> form = new Form("form", new CompoundPropertyModel<CreditCard>(creditCard));
		
		form.add(new TextField<Integer>("account"));
		form.add(new TextField<Integer>("PIN"));
		
		
		
		form.add(new SubmitLink("save") {

			@Override
			public void onSubmit() {
				super.onSubmit();
				creditCard.setBalance(0);
				creditCard.setVariableLock(true);
				clientDao.update(oper.addCreditCard(creditCard, client));
					setResponsePage(new AuthorizationPage());
				}
			});

		form.add(new Link("cancel") {

			public void onClick() {
				setResponsePage(new AuthorizationPage());
			}

		});
		
		add(new Link("ListClients")
		{

			@Override
			public void onClick() {
				setResponsePage(new ListClientsPage(client.getInfoUser()));
				
			}
			
		});
		
		add(new Link("exit")
		{

			@Override
			public void onClick() {
				setResponsePage(new AuthorizationPage());
				
			}
			
		});
		
		add(form);
	}
	
	

}
